/**
 * @param {number} num
 * @return {boolean}
 */
var isPerfectSquare = function(num) {
  if (num <= 1) {
    return true
  }
  var left = 1;
  var right = num
  while(left<right) {
    var mid = parseInt((left + right) / 2)
    var temp = mid * mid
    if (temp == num) {
      return true
    } else if (temp < num) {
      left = mid+1
    } else {
      right = mid-1
    }
  }
};